/**
 * NextVisual
 */
/**
 * NextVisual
 */
package com.reportgear.report.print.pane;

import java.awt.GridBagLayout;

import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.abbp.swing.layout.LayoutUtils;
import net.nextvisual.report.start.PageParameter;

/**
 * 分页属性
 * 
 * @version 1.0
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since 销售宝 2.0
 * 
 *        <pre>
 * 历史：
 *      建立: 2013-8-31 lexloo
 * </pre>
 */
public class PagingPage extends JPanel {
    /**
     * UID
     */
    private static final long serialVersionUID = 7496340062709129977L;
    /**
     * 是否分页打印
     */
    private JCheckBox chkPagePring = new JCheckBox();
    /**
     * 分页类型
     */
    private JComboBox cbxPageType = new JComboBox(new String[]{"成本中心", "组织机构"});

    public PagingPage() {
        this.setLayout(new GridBagLayout());

        if (PageParameter.INSTANCE.isPaging()) {
            chkPagePring.setSelected(true);
        }

        cbxPageType.setSelectedIndex(PageParameter.INSTANCE.getPageType());
        this.add(new JLabel("分页打印", JLabel.RIGHT), LayoutUtils.newGridBagConstraints(0, 0));
        this.add(chkPagePring, LayoutUtils.newGridBagConstraints(1, 0));

        this.add(new JLabel("分页依据", JLabel.RIGHT), LayoutUtils.newGridBagConstraints(0, 1));
        this.add(cbxPageType, LayoutUtils.newGridBagConstraints(1, 1));
    }

    /**
     * 更新设置信息
     */
    public boolean updatePageInfo() {
        PageParameter pp = PageParameter.INSTANCE;
        boolean paging = chkPagePring.isSelected();
        int index = cbxPageType.getSelectedIndex();
        if (pp.isPaging() == paging) {
            if (pp.getPageType() == index) {
                return false;
            }
        }

        PageParameter.INSTANCE.setPaging(paging);
        PageParameter.INSTANCE.setPageType(index);

        return true;
    }
}
